package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.base.Page;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.web.bind.annotation.*;

@Api(tags = "品牌表控制器")
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;


    //分页查询品牌信息
    @GetMapping("/{pageNum}/{pageSize}")
    public Result getBaseTrademarkByPage(@PathVariable Long pageNum,
                                         @PathVariable Long pageSize) {


       Page<BaseTrademark> baseTrademarkByPage =baseTrademarkService.getBaseTrademarkByPage(pageNum,pageSize);
        return Result.ok(baseTrademarkByPage);
    }

    //添加品牌信息
    @PostMapping("/save")
    public Result saveBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.saveBaseTrademark(baseTrademark);
        return Result.ok();
    }
    //删除品牌信息
    @DeleteMapping("/remove/{id}")
    public Result deletBaseTrademark(@PathVariable Long id){
        baseTrademarkService.deletBaseTrademark(id);
        return Result.ok();
    }
    //修改商品时的数据回显
    @GetMapping("/get/{id}")
    public Result getBaseTrademark(@PathVariable Long id){
        BaseTrademark  baseTrademark  =baseTrademarkService.getBaseTrademark(id);
        return Result.ok(baseTrademark);
    }
    //修改商品
    @PutMapping("/update")
    public Result updateBaseTrademark(@RequestBody  BaseTrademark baseTrademark){
       baseTrademarkService.updateBaseTrademark(baseTrademark);
        return Result.ok();
    }

}
